import * as types from './mutation-types'
import WebSocketClient from '../lib/websocket'

const mutations = {
  [types.SET_SID] (state, sid) {
    state.sid = sid
  },
  [types.SET_ISLOGIN] (state, isLogin) {
    state.isLogin = isLogin
  },
  [types.SET_USER_INFO] (state, userInfo) {
    if (userInfo === '') return
    state.userInfo = userInfo
    localStorage.setItem('frontUserInfo', JSON.stringify(userInfo))
  },
  [types.SET_TOKEN] (state, token) {
    state.token = token
    localStorage.setItem('frontToken', token)
  },
  [types.SET_HIDE] (state, isHide) {
    state.isHide = isHide
  },
  [types.INIT_WEBSOCKET] (state, config) {
    state.ws = new WebSocketClient(config)
    state.ws.init()
  },
  [types.SET_MESSAGE] (state, value) {
    state.num = value
  },
  [types.SET_CHATOBJ] (state, obj) {
    state.chatObj = obj
  }
}


export default mutations